<!-- 会员成员列表 -->
<template>
    <a-modal :maskClosable="false" title="选择审批人" centered :destroyOnClose="true" :width="800" v-model="visible"
        @ok="handleAddAttache">
        <s-table ref="table" size="default" rowKey="userId" :columns="columns" :data="loadData"
            :rowSelection="type === 'add' ? { selectedRowKeys: selectedRowKeys, onChange, onSelect, onSelectAll } : null">
        </s-table>
    </a-modal>
</template>

<script>
import { STable } from '@/components'
import { attacheAdd, pageAttacheList } from '@/api/member/commissioner'
import { getUserList } from '@/api/system/system'
export default {
    components: {
        STable
    },
    data() {
        return {
            type: 'add',
            visible: false,
            attacheType: undefined,
            pagination: {
                current: 1,
                pageSize: 10
            },
            columns: [
                {
                    title: '姓名',
                    dataIndex: 'userName'
                },
                {
                    title: '角色',
                    dataIndex: 'roleName'
                },
                // {
                //     title: '头像',
                //     dataIndex: 'logo'
                // },
                {
                    title: '手机号',
                    dataIndex: 'phonenumber'
                }
            ],
            loadData: parameter => {
                return getUserList(Object.assign(parameter))
            },
            selectedRowKeys: []
        }
    },
    computed: {},
    watch: {},
    methods: {
        open(keys, rows) {
            // this.type = obj.type
            this.selectedRowKeys = keys
            this.selectedRows = [...rows]
            this.visible = true
        },
        // see() {
        //     this.title = obj.title
        //     this.attacheType = obj.data.attacheType
        //     this.visible = true
        // },
        onChange(selectedRowKeys, rows) {
            // console.log('selectedRowKeys-->', selectedRowKeys, rows)
            this.selectedRowKeys = selectedRowKeys;
            // this.selectedRows = rows
        },
        onSelect(record, selected) {
            console.log('record-->', record)
            let index = this.selectedRows.findIndex(f => f.userId === record.userId)
            if (selected && index === -1) {
                this.selectedRows.push(record)
            } else if (!selected && index != -1) {
                this.selectedRows.splice(index, 1)
            }
        },
        onSelectAll(selected, selectedRows, changeRows) {
            // console.log(selected, selectedRows, changeRows)
            changeRows.map(item => {
                this.onSelect(item, selected)
            })
        },

        async handleAddAttache() {
            if (!this.selectedRowKeys.length) return this.$message.error('请选择审批人')
            this.$emit('getApprovalUser', [...this.selectedRows])
            this.visible = false
        }
    },
    created() {

    },
    mounted() {

    },
}
</script>
<style scoped>

</style>